<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="mobile">
        <el-select v-model="queryParams.status" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="feedbackList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="10%" align="center" /> -->
      <!-- 显示数据：incident_id(事件key) 、trade_no(交易号)、crash_file(奔溃日志文件)、mobile(手机号)、status(奖励状态) -->
      <!-- 联系方式列，适当调整宽度 -->
      <el-table-column label="手机号" align="center" prop="mobile">
      </el-table-column>
      <el-table-column
        label="事件key"
        align="center"
        prop="incidentId"
        width="400vh"
      />

      <!-- 反馈内容列，设置最多显示4行 -->
      <el-table-column label="交易号" align="center" prop="tradeNo">
        <template slot-scope="scope">
          <div class="content-cell" :title="scope.row.tradeNo">
            {{ scope.row.tradeNo }}
          </div>
        </template>
      </el-table-column>
      <el-table-column label="奔溃日志文件" align="center" prop="crashFile">
        <template slot-scope="scope">
          <div
            class="content-cell openDom"
            :title="scope.row.crashFile"
            @click="handleAdd(scope.row.crashFile)"
          >
            查看文件
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <div class="content-cell" :title="scope.row.status">
            {{
              scope.row.status == 0
                ? "未审核"
                : scope.row.status == 1
                ? "审核通过"
                : "审核不通过"
            }}
          </div>
        </template>
      </el-table-column>
      <!-- 创建时间列，已经设置宽度 -->

      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="400vh"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.current"
      :limit.sync="queryParams.size"
      @pagination="getList"
    />

    <!-- 添加或修改用户反馈对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1200px"
      append-to-body
    >
      {{ crashFile }}
    </el-dialog>
  </div>
</template>

<script>
import { consPage } from "@/api/crashLog/crashLog";
const regex = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/;
export default {
  name: "Feedback",
  dicts: ["sys_feedback_type"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      options: [
        {
          value: "0",
          label: "未审核",
        },
        {
          value: "1",
          label: "审核通过",
        },
        {
          value: "2",
          label: "审核不通过",
        },
      ],
      value: "",
      // 用户反馈表格数据
      feedbackList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      crashFile: "",
      // 查询参数
      queryParams: {
        current: 1,
        size: 20,
        mobile: null,
        source: 2,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户反馈列表 */
    getList() {
      this.loading = true;

      consPage(this.queryParams).then((response) => {
        this.feedbackList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        uid: null,
        mobile: null,
        module: null,
        source: null,
        types: null,
        content: null,
        videoFileIds: null,
        imageFileIds: null,
        createTime: null,
        modifyTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      if (!regex.test(this.queryParams.mobile)&&this.queryParams.mobile!=null) {
        this.$message('请输入完整手机号搜索');
        return false
      }

      this.queryParams.current = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd(item) {
      console.log(item);
      this.reset();
      this.open = true;
      this.title = "奔溃日志文件";
      this.crashFile = item;
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "web/feedback/export",
        {
          ...this.queryParams,
        },
        `feedback_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style scoped>
.content-cell {
  max-height: 12em; /* 4行的高度 */
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 7; /* 限制显示7行 */
  -webkit-box-orient: vertical;
}

.content-cell:hover {
  white-space: normal;
  word-wrap: break-word;
}
.openDom {
  color: #1890ff;
}
::v-deep .el-dialog__body {
  height: 80vh;
  overflow: auto;
}
</style>
